package com.ruanxie.json.deserializer;

import com.alibaba.fastjson.parser.DefaultJSONParser;
import com.alibaba.fastjson.parser.JSONToken;
import com.alibaba.fastjson.parser.deserializer.ObjectDeserializer;

import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.Map;

public class ClassHourMarkDeserializer implements ObjectDeserializer {
    private static final Map<String, String> classHourMap = new HashMap<>();
    static {
        classHourMap.put("★", "理论");
        classHourMap.put("☆", "实验");
        classHourMap.put("◆", "实习");
        classHourMap.put("■", "实践");
        classHourMap.put("〇", "课外");
    }

    @Override
    public <T> T deserialze(DefaultJSONParser defaultJSONParser, Type type, Object o) {
        String classHourMark = defaultJSONParser.parseObject(String.class);
        String classHourName = classHourMap.getOrDefault(classHourMark, "未知类型");
        return (T) classHourName;
    }

    @Override
    public int getFastMatchToken() {
        return JSONToken.LITERAL_STRING;
    }
}
